package cn.itcast.service.impl;

import cn.itcast.domain.Client;
import cn.itcast.mapper.ClientMapper;
import cn.itcast.service.ClientService;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class ClientServiceImpl implements ClientService {
    @Autowired
    private ClientMapper mapper;

    /**
     * 查询住房客户
     * @param currentPage
     * @param rows
     * @return
     */
    @Override
    public List<Client> findNow(String currentPage,String rows) {
        int pageNum = Integer.parseInt(currentPage);
        int pageSize = Integer.parseInt(rows);
        PageHelper.startPage(pageNum,pageSize);
        return mapper.findNow();
    }

    /**
     * 查询历史客户
     * @param currentPage
     * @param rows
     * @return
     */
    @Override
    public List<Client> findHis(String currentPage,String rows) {
        int pageNum = Integer.parseInt(currentPage);
        int pageSize = Integer.parseInt(rows);
        PageHelper.startPage(pageNum,pageSize);
        return mapper.findHis();
    }


    /**
     * 新增客户
     * @param client
     * 传入前台表单中的数据
     */
    @Override
    public void add(Client client) {
        //增加客户
        mapper.add(client);
        //中间表添加信息

        //更改房间flag

    }


    /**
     *
     * @param clientId
     * 点击图片回传id
     * @return
     * 将回显的数据返回给前台
     */
    @Override
    public Client findClient(Integer clientId) {
        return mapper.findClient(clientId);
    }

    @Override
    public void deleteClient(Client client) {
        mapper.deleteClient(client);
    }

    /**
     * 查询新增客户的id
     * @param client
     * @return
     */
    @Override
    public int findCid(Client client) {
      return   mapper.findCid(client);
    }

    @Override
    public Date findClientDate(int roomNumber) {
        Date date = mapper.findclientdate(roomNumber);
        return date;
    }

    @Override
    public void updateFlagById(int cid) {
        mapper.updateFlagById(cid);
    }

}
